import { downloadFile, queryUrlParams } from '@/utils/index'
import request from '@/utils/request'
import { Loading } from 'element-ui'

// 药房药品数据导出
export function exportDrugStatis(data) {
  const loading = Loading.service({
    text: '正在处理...'
  })
  request({
    url: '/drugStatistics/export',
    responseType: 'blob',
    method: 'post',
    data
  }).then(result => {
    downloadFile(result, '药房药品', 'xlsx')
    loading.close()
  }).catch(() => {
    loading.close()
  })
}

// 销售统计-头部固定数据
export function infoSalesDateTop() {
  return request({
    url: '/drugStatistics/infoSalesDateTop',
    method: 'post'
  })
}

// 导出医生处方
export function outInfoSalesDoc(data) {
  const param = queryUrlParams(data)
  const loading = Loading.service({
    text: '正在处理...'
  })
  return request({
    url: '/drugStatistics/outInfoSalesDoc?' + param,
    responseType: 'blob',
    method: 'get'
  }).then(result => {
    downloadFile(result, '医生处方', 'xlsx')
    loading.close()
  }).catch(() => {
    loading.close()
  })
}

// 导出销售统计
export function outInfoSalesDate(data) {
  const param = queryUrlParams(data)
  const loading = Loading.service({
    text: '正在处理...'
  })
  return request({
    url: '/drugStatistics/outInfoSalesDate?' + param,
    responseType: 'blob',
    method: 'get'
  }).then(result => {
    downloadFile(result, '销售统计', 'xlsx')
    loading.close()
  }).catch(() => {
    loading.close()
  })
}
